home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
mac
/
LOGIC Apple II 5.25" Library - Pascal
/
PAS027.dsk
/
MICROMODEM.TEXT.txt
< prev
next >
Wrap
Text File
|
2012-02-16
|
7KB
|
333 lines
(*$S+*)
UNIT MICROMODEM;
INTERFACE
CONST SECONDS=100;
TYPE MODEMSLOT=1..3;
BAUDRATE=(RATE110,RATE300);
PARITYKIND=(EVENPARITY,ODDPARITY,NOPARITY);
MODETYPE=(ANSWER,ORIGINATE);
L7OR8=7..8;
S1OR2=1..2;
UMODEMCONTROL=PACKED RECORD
ACIACLK: 0..3;
WORDSEL: 0..7;
XMITCTL: 0..3;
RIE: BOOLEAN;
BRS: BAUDRATE;
TXE: BOOLEAN;
MODE: MODETYPE;
NOTRESET: BOOLEAN;
SELFTEST: BOOLEAN;
UNUSEDBITS: 0..3;
OFFHOOK: BOOLEAN;
END;
UMODEMSTATUS=PACKED RECORD
RDRF: BOOLEAN;
TDRE: BOOLEAN;
NOTDCD: BOOLEAN;
NOTCTS: BOOLEAN;
FE: BOOLEAN;
OVRN: BOOLEAN;
PE: BOOLEAN;
IRQ: BOOLEAN;
UNUSEDBITS: 0..127;
NOTRI: BOOLEAN;
END;
VAR MODEMCONTROL: UMODEMCONTROL;
(* PHONE LINE CONTROL *)
PROCEDURE PICKUP;
PROCEDURE HANGUP;
FUNCTION RINGING: BOOLEAN;
PROCEDURE DIAL(NUMBER:STRING);
(* MODEM CONTROL *)
PROCEDURE SETMODE(NEWMODE:MODETYPE);
PROCEDURE TXON;
PROCEDURE TXOFF;
FUNCTION CARRIER: BOOLEAN;
(* ACIA CONTROL *)
PROCEDURE SENDBREAK(TIME:INTEGER);
PROCEDURE SETRATE(NEWRATE:BAUDRATE);
FUNCTION MODEMINPUT: BOOLEAN;
FUNCTION MODEMREADY: BOOLEAN;
PROCEDURE CHARFORMAT(CHARLEN:L7OR8; STOPBITS:S1OR2; PARITY:PARITYKIND);
(* FUNDAMENTAL ROUTINES *)
PROCEDURE USEMODEM(SLOT:MODEMSLOT);
PROCEDURE DCHCONTROL(CTL:UMODEMCONTROL);
PROCEDURE DCHSTATUS(VAR STATUS:UMODEMSTATUS);
PROCEDURE DELAY10MS(TIME:INTEGER);
(* STRING INPUT ROUTINE *)
PROCEDURE READMODEM(VAR MODEMIN,MODEMOUT:INTERACTIVE; VAR S:STRING;
VAR CH:CHAR);
IMPLEMENTATION
CONST IOPAGE=192; (* =$C0 *)
TYPE CHARPTR=^ CHAR;
VAR FINDMODEM: MODEMSLOT;
FOUND,MISSING: BOOLEAN;
FOOL: RECORD
CASE BOOLEAN OF
TRUE: (ADDR: PACKED RECORD
LO: 0..255;
HI: 0..255;
END);
FALSE: (P: ^ CHAR);
END;
MODEMCS: CHARPTR;
ACIADATA: CHARPTR;
PROCEDURE DCHCTL(MODEMADDR:CHARPTR; CTL:UMODEMCONTROL);
EXTERNAL;
PROCEDURE DCHSTS(MODEMADDR:CHARPTR; VAR STATUS:UMODEMSTATUS);
EXTERNAL;
FUNCTION ISDCHAYES(SLOT:MODEMSLOT): BOOLEAN;
EXTERNAL;
PROCEDURE DCHCONTROL;
BEGIN
DCHCTL(MODEMCS,CTL);
END;
PROCEDURE DCHSTATUS;
BEGIN
DCHSTS(MODEMCS,STATUS);
END;
PROCEDURE DELAY10MS;
CONST CNT10MS=15;
VAR I,J: INTEGER;
BEGIN
FOR I:=TIME DOWNTO 0 DO
FOR J:=1 TO CNT10MS DO;
END;
PROCEDURE PICKUP;
BEGIN
DELAY10MS(1*SECONDS);
MODEMCONTROL.OFFHOOK:=TRUE;
DCHCONTROL(MODEMCONTROL);
DELAY10MS(2*SECONDS);
END;
PROCEDURE HANGUP;
BEGIN
MODEMCONTROL.OFFHOOK:=FALSE;
DCHCONTROL(MODEMCONTROL);
END;
FUNCTION RINGING;
VAR STATUS: UMODEMSTATUS;
BEGIN
DCHSTATUS(STATUS);
RINGING:=NOT STATUS.NOTRI;
END;
PROCEDURE DIAL;
VAR STRPTR,DIGIT: INTEGER;
PROCEDURE DIALDIGIT(COUNT:INTEGER);
VAR I: INTEGER;
BEGIN
FOR I:=1 TO COUNT DO BEGIN
MODEMCONTROL.OFFHOOK:=FALSE;
DCHCONTROL(MODEMCONTROL);
DELAY10MS(5);
MODEMCONTROL.OFFHOOK:=TRUE;
DCHCONTROL(MODEMCONTROL);
DELAY10MS(3);
END;
DELAY10MS(70);
END;
BEGIN
FOR STRPTR:=1 TO LENGTH(NUMBER) DO BEGIN
DIGIT:=POS(COPY(NUMBER,STRPTR,1),'1234567890*#');
IF DIGIT<>0 THEN DIALDIGIT(DIGIT)
ELSE IF NUMBER[STRPTR]='.' THEN DELAY10MS(1*SECONDS)
ELSE IF NUMBER[STRPTR]='/' THEN BEGIN
MODEMCONTROL.OFFHOOK:=FALSE;
DCHCONTROL(MODEMCONTROL);
DELAY10MS(50);
MODEMCONTROL.OFFHOOK:=TRUE;
DCHCONTROL(MODEMCONTROL);
DELAY10MS(2*SECONDS);
END;
END;
END;
PROCEDURE SETMODE;
BEGIN
MODEMCONTROL.MODE:=NEWMODE;
DCHCONTROL(MODEMCONTROL);
END;
PROCEDURE TXON;
BEGIN
MODEMCONTROL.TXE:=TRUE;
DCHCONTROL(MODEMCONTROL);
END;
PROCEDURE TXOFF;
BEGIN
MODEMCONTROL.TXE:=FALSE;
DCHCONTROL(MODEMCONTROL);
END;
FUNCTION CARRIER;
VAR STATUS: UMODEMSTATUS;
CH: CHAR;
BEGIN
DCHSTATUS(STATUS);
IF STATUS.NOTDCD THEN BEGIN
CH:=ACIADATA^;
DCHSTATUS(STATUS);
END;
CARRIER:=NOT STATUS.NOTDCD;
END;
PROCEDURE SENDBREAK;
BEGIN
MODEMCONTROL.XMITCTL:=3;
DCHCONTROL(MODEMCONTROL);
DELAY10MS(TIME);
MODEMCONTROL.XMITCTL:=0;
DCHCONTROL(MODEMCONTROL);
END;
PROCEDURE SETRATE;
BEGIN
MODEMCONTROL.BRS:=NEWRATE;
DCHCONTROL(MODEMCONTROL);
END;
PROCEDURE CHARFORMAT;
BEGIN
IF CHARLEN=7 THEN
IF PARITY<>NOPARITY THEN
MODEMCONTROL.WORDSEL:=2*(1-STOPBITS DIV 2)+ORD(PARITY)
ELSE (* NOPARITY IS ILLEGAL *)
ELSE (* CHARLEN=8 *)
IF PARITY=NOPARITY THEN
MODEMCONTROL.WORDSEL:=4+(1-STOPBITS DIV 2)
ELSE IF STOPBITS=1 THEN
MODEMCONTROL.WORDSEL:=6+ORD(PARITY)
ELSE (* STOPBITS=2 IS ILLEGAL *);
DCHCONTROL(MODEMCONTROL);
END;
FUNCTION MODEMINPUT;
VAR STATUS: UMODEMSTATUS;
BEGIN
DCHSTATUS(STATUS);
MODEMINPUT:=STATUS.RDRF;
END;
FUNCTION MODEMREADY;
VAR STATUS: UMODEMSTATUS;
BEGIN
DCHSTATUS(STATUS);
MODEMREADY:=STATUS.TDRE;
END;
PROCEDURE READMODEM;
CONST CR=13; BS=8; DEL=127; CAN=24; BEL=7;
VAR CURPOS,I: INTEGER;
PROCEDURE RUBOUT;
BEGIN
WRITE(MODEMOUT,CHR(BS),' ',CHR(BS));
END;
BEGIN
S:='';
CURPOS:=1;
REPEAT
WHILE CARRIER AND NOT MODEMINPUT DO;
IF CARRIER THEN BEGIN
READ(MODEMIN,CH);
IF EOLN(MODEMIN) THEN CH:=CHR(CR);
IF ORD(CH)>=128 THEN CH:=CHR(ORD(CH)-128);
IF (CH=CHR(BS)) OR (CH=CHR(DEL)) THEN BEGIN
IF CURPOS<=1 THEN WRITE(MODEMOUT,CHR(BEL))
ELSE BEGIN
RUBOUT;
CURPOS:=CURPOS-1;
END;
CH:=CHR(BS);
END
ELSE IF CH=CHR(CAN) THEN BEGIN
IF CURPOS<=1 THEN WRITE(MODEMOUT,CHR(BEL))
ELSE BEGIN
FOR I:=CURPOS DOWNTO 1 DO RUBOUT;
CURPOS:=1;
END;
CH:=CHR(BS);
END
ELSE IF CH=CHR(CR) THEN WRITELN(MODEMOUT)
ELSE IF CH>=' ' THEN WRITE(MODEMOUT,CH);
END
ELSE CH:=CHR(DEL);
IF CH>=' ' THEN BEGIN
INSERT(' ',S,CURPOS);
S[CURPOS]:=CH;
CURPOS:=CURPOS+1;
END;
UNTIL (CH<' ') AND (CH<>CHR(BS)) OR (CH=CHR(DEL));
END;
PROCEDURE USEMODEM;
VAR TEMP: INTEGER;
BEGIN
TEMP:=SLOT*16+128;
FOOL.ADDR.HI:=IOPAGE;
FOOL.ADDR.LO:=TEMP+5;
MODEMCS:=FOOL.P;
FOOL.ADDR.LO:=TEMP+7;
ACIADATA:=FOOL.P;
END;
BEGIN
FINDMODEM:=3;
FOUND:=FALSE;
MISSING:=FALSE;
WHILE NOT FOUND AND NOT MISSING DO BEGIN
FOUND:=ISDCHAYES(FINDMODEM);
MISSING:=NOT FOUND AND (FINDMODEM=1);
IF NOT MISSING AND NOT FOUND THEN FINDMODEM:=FINDMODEM-1;
END;
IF FOUND THEN USEMODEM(FINDMODEM)
ELSE BEGIN
WRITELN('NO MICROMODEM II');
EXIT(PROGRAM);
END;
WITH MODEMCONTROL DO BEGIN
ACIACLK:=3;
WORDSEL:=4;
XMITCTL:=0;
RIE:=FALSE;
BRS:=RATE300;
TXE:=FALSE;
MODE:=ANSWER;
NOTRESET:=FALSE;
SELFTEST:=FALSE;
UNUSEDBITS:=0;
OFFHOOK:=FALSE;
END;
DCHCONTROL(MODEMCONTROL);
MODEMCONTROL.ACIACLK:=1;
MODEMCONTROL.NOTRESET:=TRUE;
DCHCONTROL(MODEMCONTROL);
END.